package hasthi.tools;

import hasthi.common.HasthiException;
import hasthi.common.HasthiException.FaultCode;

import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;

public class FailureDetectionTools {
    public static boolean isSocketUp(String urlAsStr) throws HasthiException{
        try {
            URL url = new URL(urlAsStr);
             Socket socket = new Socket(url.getHost(),url.getPort());
             socket.close();
             return true;
        } catch (MalformedURLException e) {
            throw new HasthiException(e,FaultCode.InvaliedLocalArgumnet);
        } catch (Exception e) {
            return false;
        }
    }
}
